package cn.sdormitory.attendance.service.impl;

import cn.sdormitory.attendance.dao.HolidayConfigDao;
import cn.sdormitory.attendance.entity.HolidayConfig;
import cn.sdormitory.attendance.service.HolidayConfigService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author: lx
 * @date: 2023/9/20 14:59
 * @description:
 */
@Service
public class HolidayConfigServiceImpl extends ServiceImpl<HolidayConfigDao, HolidayConfig> implements HolidayConfigService {

    @Autowired
    HolidayConfigDao holidayConfigDao;

    @Override
    public int createHoliday(HolidayConfig holidayConfig) {
//        String holidayStart = holidayConfig.getHolidayStart();
//        String holidayEnd = holidayConfig.getHolidayEnd();
//        Long deptId = holidayConfig.getDeptId();
//
//        holidayConfigDao.selectHolidayIsRepeat(holidayStart,holidayEnd,deptId);

        return holidayConfigDao.insert(holidayConfig);
    }

    @Override
    public IPage<HolidayConfig> findHolidayPageList(HolidayConfig query) {
        int count = holidayConfigDao.findRulesPageListCount(query);
        int startNum = (query.getPageNum() - 1) * query.getPageSize();
        List<HolidayConfig> list = holidayConfigDao.findRulesPageList(query,startNum,query.getPageSize());
        IPage<HolidayConfig> page = new Page<>();
        page.setTotal(count);
        page.setRecords(list);
        return page;
    }

    @Override
    public HolidayConfig getHolidayById(Long id) {
        return this.baseMapper.selectById(id);
    }

    @Override
    public int deleteHolidayById(Long id) {
        return this.baseMapper.deleteById(id);
    }

    @Override
    public int updateHoliday(HolidayConfig holiday) {
        return this.baseMapper.updateById(holiday);
    }
}
